package com.sctvcloud.zhaohua_sd.ui.fragment;

import android.app.ActivityOptions;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.githang.statusbar.StatusBarCompat;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.gridsum.tracker.GridsumWebDissector;
import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.ListUtils;
import com.ruihang.generalibrary.utils.SharedPreferencesUtil;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.base.BaseActivity;
import com.sctvcloud.zhaohua_sd.base.BaseFragment;
import com.sctvcloud.zhaohua_sd.beans.FocusColumn;
import com.sctvcloud.zhaohua_sd.beans.HomeEvent;
import com.sctvcloud.zhaohua_sd.http.AbsListNetCallback;
import com.sctvcloud.zhaohua_sd.http.NetUtils;
import com.sctvcloud.zhaohua_sd.ui.activities.AddColumnActivity;
import com.sctvcloud.zhaohua_sd.ui.activities.LookBackActivity;
import com.sctvcloud.zhaohua_sd.ui.activities.SearchActivity;
import com.sctvcloud.zhaohua_sd.ui.adapter.HomePagerAdapter;
import com.sctvcloud.zhaohua_sd.ui.dialog.ChooseCityFuncFragment;

import com.sctvcloud.zhaohua_sd.application.Cache;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.sctvcloud.zhaohua_sd.ui.activities.AddColumnActivity.COLUMN_LIST;

/**
 * Created by Administrator on 2017/6/19 0019.
 * 首页
 */
public class HomeFragment extends BaseFragment implements OnTabSelectListener {

    private final String ColumnUrl = "sctv/index.json";
    private static HomeFragment instance;
    @BindView(R.id.normal_home_top)
    protected RelativeLayout normalTitle;
    @BindView(R.id.lz_home_top)
    protected RelativeLayout lzTitle;
    @BindView(R.id.lz_title_left_logo)
    protected ImageView lzLeftLogo;
    @BindView(R.id.title_top_logo_dingwei)
    protected ImageView homeLogD;
    @BindView(R.id.title_top_logo)
    protected ImageView homeLog;
    @BindView(R.id.lz_title_top_logo)
    protected ImageView lzhomeLog;
    @BindView(R.id.title_txt)
    protected CustomFontTextView titleTxt;
    @BindView(R.id.home_tablay)
    protected SlidingTabLayout home_tablay;
    @BindView(R.id.home_content_vp)
    protected ViewPager home_content_vp;
    @BindView(R.id.home_top)
    protected ViewGroup topLay;
    @BindView(R.id.home_top_lay_tab)
    protected ViewGroup tabLay;
    @BindView(R.id.home_add_iv)
    protected ImageView add_column;
    @BindView(R.id.home_content_ll)
    protected LinearLayout content_ll;
    @BindView(R.id.home_no_data_ct)
    protected CustomFontTextView no_data;
    private HomePagerAdapter homePagerAdapter;
    private ArrayList<FocusColumn> thisColumnList;
    public static final int REQUEST_CODE = 1;
    public static final String COLUMN_DATA = "column_data";
    private Gson gson;
    public static final String NET_TAG = "chooseCityFuncFragment";
    private List<FocusColumn> al_column;
    private List<FocusColumn> ot_column;
    private String playBackUrl, contributeUrl;
    private boolean isShowLZ = false;//是否是显示泸州市的新闻
    private FragmentManager fragmentManager;
    private int currentTabPosition = 0;

    private String lastColumnId = "";//切换到其他模块时，记录首页的栏目ID

    private String cityCode = "";
    private static final String IS_EXHCNAGE = "IS_EXCHANGE";
    private static final String LOCATION_CITY = "LOCATION_CITY";
    private String anouncementUrl;
    private boolean isResetTab = false;

    public static HomeFragment getInstance() {
        return instance;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        ButterKnife.bind(this, view);
        fragmentManager = this.getChildFragmentManager();
        EventBus.getDefault().register(this);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //初始化请求栏目数据
        getColumn();
        instance = this;

    }

    @Override
    public void onResume() {
        super.onResume();
//        exchangeShowLZ(Cache.getInstance().isCityShow(), true);
//        if (isResetTab) {
//            resetTabIndex();
//            isResetTab = false;
//        }
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onjump(HomeEvent messageEvent) {
        if (null != messageEvent ) {
            JLog.e("Log","messageEvent.getPosition():  "+messageEvent.getPosition());
            for(FocusColumn column:thisColumnList){
                if(column.getChannelId()==messageEvent.getPosition()){
                    int id=thisColumnList.indexOf(column);
                    Cache.getInstance().setCurrentChannelId(String.valueOf(id));
                    setCurrentSelectIndex(id);
                }
            }
        }
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        ColumnBaseFragment cbf = getCurrentFragment();
        if (cbf != null&&!isResetTab) {
            cbf.setParentShowing(!hidden);
            cbf.onHiddenChanged(hidden);
        }
        if (hidden) {
            lastColumnId = Cache.getInstance().getCurrentChannelId();
        } else {
            if (isResetTab) {
                resetTabIndex();
                isResetTab = false;
            }
            StatusBarCompat.setStatusBarColor(getActivity(), getResources().getColor(R.color.white));
            Cache.getInstance().setCurrentChannelId(lastColumnId);
        }

    }

    /**
     * 获取首页栏目数据
     */
    private void getColumn() {
        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), ColumnUrl, new AbsListNetCallback<FocusColumn>(null) {
            @Override
            public void onSuc(List<FocusColumn> fChannels) {
//                JLog.e("" + fChannels);
                closeProgress();
                setData(fChannels);
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                closeProgress();
                no_data.setVisibility(View.VISIBLE);
                content_ll.setVisibility(View.GONE);
            }
        });
    }

    /**
     * 加载 首页中的各个栏目页面
     *
     * @param fChannels
     */
    private void setData(List<FocusColumn> fChannels) {
        if (ListUtils.isListValued(fChannels)) {
            content_ll.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
            Cache.getInstance().setfChannels(fChannels);
            FocusColumn hRColumn = null;//高层 栏目
            for (int i = 0; i < fChannels.size(); i++) {
                FocusColumn column = fChannels.get(i);
                String channelType = column.getChannelType();
                column.setChoice(true);
                if (channelType.equals("8")) { //搜索
//                    searchUrl = column.getChannelUrl();
                    fChannels.remove(column);
                    i--;
                } else if (channelType.equals("9")) {//节目回看
                    playBackUrl = column.getChannelUrl();
                    fChannels.remove(column);
                    i--;
                } else if (channelType.equals("10")) {//投稿
                    contributeUrl = column.getChannelUrl();
                    BaseFragment.setRebllionUrl(contributeUrl);
                    fChannels.remove(column);
                    i--;
                }
                else if (channelType.equals("13")) {//昭化就业
                    if(column.getChannelId()==2011){
                        Cache.getInstance().setJobId(column.getChannelId());
                        Cache.getInstance().setJobUrl(column.getChannelUrl());
                    }
                }
            }
//            if (null != hRColumn) {
//                //调整高层栏目所在位置
//                fChannels.add(1, hRColumn);
//            }
            List<FocusColumn> handleList = HomePagerAdapter.handleColumn(fChannels);
            List<FocusColumn> list = compareSaveData(handleList);
            if (ListUtils.isListValued(list)) {
                thisColumnList = new ArrayList<>();
                thisColumnList.addAll(list);
                //初始化栏目ID
                String id = getCurrentColumnId(0);
                Cache.getInstance().setCurrentChannelId(id);
            }

            boolean b = true;
            int s = -1;
            if (homePagerAdapter == null) {
                homePagerAdapter = new HomePagerAdapter(getChildFragmentManager(), list);
                setAdapterTopHeiht(true);
                home_content_vp.setAdapter(homePagerAdapter);
                home_content_vp.setOffscreenPageLimit(1);
                home_tablay.setViewPager(home_content_vp);
                s = homePagerAdapter.getCount();
            } else {
                s = homePagerAdapter.getCount();
                setAdapterTopHeiht(true);
                homePagerAdapter.setData(list);
                b = s != homePagerAdapter.getCount();
            }
            home_tablay.setOnTabSelectListener(this);
//            JLog.e("uuju  will to refresh column  b="+b+"   s="+s);
            refreshColumnTab(b);

        } else {
            no_data.setVisibility(View.VISIBLE);
            content_ll.setVisibility(View.GONE);
        }
    }

    /**
     * 获取当前正显示的Fragment
     *
     * @return
     */
    public ColumnBaseFragment getCurrentFragment() {
        if (home_content_vp == null || homePagerAdapter == null || homePagerAdapter.getCount() == 0) {
            return null;
        }
        ColumnBaseFragment cbf = homePagerAdapter.getFragmentByPos(home_content_vp.getCurrentItem());
        JLog.e("ffsf " + cbf);
        return cbf;
    }

    public ColumnBaseFragment getCurrentFragment(int index) {
        if (home_content_vp == null || homePagerAdapter == null || homePagerAdapter.getCount() == 0) {
            return null;
        }
        ColumnBaseFragment cbf = homePagerAdapter.getFragmentByPos(index);
        JLog.e("ffsf " + cbf);
        return cbf;
    }

    /**
     * 刷新栏目
     *
     * @param data
     */
    private void refreshData(Intent data) {
        ArrayList<FocusColumn> al_data = (ArrayList<FocusColumn>) data.getSerializableExtra(AddColumnActivity.COLUMN);
        for (int i = 0; i < al_data.size(); i++) {
            if (!al_data.get(i).isChoice()) {
                al_data.remove(i);
                i--;
            }
        }
        if (al_data.size() != 0) {
            if (ListUtils.isListValued(al_data)) {
                thisColumnList = new ArrayList<>();
                thisColumnList.addAll(al_data);
            }
            homePagerAdapter = new HomePagerAdapter(getChildFragmentManager(), al_data);
            setAdapterTopHeiht(true);
            home_content_vp.setAdapter(homePagerAdapter);
            home_content_vp.setOffscreenPageLimit(1);
            home_tablay.setViewPager(home_content_vp);
            refreshColumnTab(true);
        }
    }

    /**
     * 刷新栏目在首页的标签
     *
     * @param b
     */
    private void refreshColumnTab(boolean b) {
        int size = homePagerAdapter.getCount();
        if (size == 0 || !b) {
            return;
        }
//        JLog.e("uuju   in refresh size="+size+"   "+home_tablay.getWidth());
//        JLog.e("uuju  " + getResources().getDimension(R.dimen.tab_home_padding_m)
//                + "   " + getResources().getDimensionPixelOffset(R.dimen.tab_home_padding_m)
//                + "   " + getResources().getDimensionPixelSize(R.dimen.tab_home_padding_m) +
//                "\n   " + DensityUtil.dip2px(getContext(), 8) + "   " + DensityUtil.dip2px(getContext(), 12));
//        if (size <= 7) {
//            home_tablay.setTabSpaceEqual(false);
//            home_tablay.notifyDataSetChanged();
//        } else {
        home_tablay.setTabSpaceEqual(false);
        float d = getResources().getDimension(R.dimen.tab_home_padding_m);
        if (size <= 6) {
            d = getResources().getDimension(R.dimen.tab_home_padding_l);
        } else if (size == 7) {
            d = getResources().getDimension(R.dimen.tab_home_padding);
        }
        home_tablay.setTabPaddingPx(d);
        home_tablay.notifyDataSetChanged();
        if (homePagerAdapter.getCount() > currentTabPosition) {
            home_tablay.setCurrentTab(currentTabPosition);
        } else if (currentTabPosition > 0) {
            currentTabPosition = homePagerAdapter.getCount() - 1;
            home_tablay.setCurrentTab(currentTabPosition);
        } else {
            home_tablay.setCurrentTab(0);
        }
//        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//            topLay.setVisibility(View.GONE);
//            tabLay.setVisibility(View.GONE);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
//            topLay.setVisibility(View.VISIBLE);
//            tabLay.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public boolean hasShowPlayer() {
        BaseFragment bf = getCurrentFragment();
        return bf != null && bf.hasShowPlayer();
    }

    @OnClick(value = {R.id.home_search_iv, R.id.home_look_back_tv, R.id.lz_home_look_back_tv, R.id.home_add_iv, R.id.home_no_data_ct, R.id.lz_home_search_iv})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.home_search_iv:
            case R.id.lz_home_search_iv:
                ColumnBaseFragment cbf = getCurrentFragment();
                if (cbf instanceof TvFragment) {
                    TvFragment tv = (TvFragment) cbf;
                    tv.parentTitleClick();
                }
//                Intent searchIntent = new Intent(getActivity(), SearchNewsActivity.class);
//                startActivity(searchIntent);
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), view, getString(R.string.voice_id));
// 使用 Intent 跳转界面，并传递共享对象信息
                Intent searchIntent = new Intent(getActivity(), SearchActivity.class);
                startActivity(searchIntent, options.toBundle());
                break;
            case R.id.home_look_back_tv:
            case R.id.lz_home_look_back_tv:
                Intent playBackIntent = new Intent(getActivity(), LookBackActivity.class);
                if (!TextUtils.isEmpty(playBackUrl) && playBackUrl.endsWith(".json")) {
                    playBackIntent.putExtra(BaseActivity.EX_URL, playBackUrl);
                    startActivity(playBackIntent);
                } else {
                    toast("数据错误");
                }

                break;
            case R.id.home_add_iv:
                Intent addColumnIntent = new Intent(getActivity(), AddColumnActivity.class);
                String param = (String) SharedPreferencesUtil.getParam(getActivity(), COLUMN_LIST, "");
                if (!TextUtils.isEmpty(param)) {
                    ArrayList<FocusColumn> focusColumns = initGson().fromJson(param, new
                            TypeToken<ArrayList<FocusColumn>>() {
                            }.getType());
                    addColumnIntent.putExtra(COLUMN_DATA, focusColumns);
                    startActivityForResult(addColumnIntent, REQUEST_CODE);

                } else {
                    if (ListUtils.isListValued(al_column)) {
                        addColumnIntent.putExtra(COLUMN_DATA, (Serializable) al_column);
                        startActivityForResult(addColumnIntent, REQUEST_CODE);
                    } else {
                        toast("没有更多栏目");
                    }

                }

                break;
            case R.id.home_no_data_ct:
                showProgress("数据正在加载中...");
                getColumn();
                break;
        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        final int pos = data.getIntExtra(AddColumnActivity.SELECT_POS, 0);
        if (pos > 0) {
            refreshData(data);
            final int currentPos = home_content_vp.getCurrentItem();
            home_content_vp.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (currentPos != pos) {
                        home_content_vp.setCurrentItem(pos);
                    } else {
                        home_content_vp.setCurrentItem(currentPos);
                    }
                }
            }, 200);
        } else {
            refreshData(data);
        }
    }

    @Override
    public boolean onBackPressed() {
        ColumnBaseFragment f = getCurrentFragment();
        if (f != null && f.onBackPressed()) {
            return true;
        }
        return super.onBackPressed();
    }

    private Gson initGson() {
        if (gson == null) {
            gson = new Gson();
        }
        return gson;
    }


    private void setAdapterTopHeiht(boolean isNewInstance) {
        if (isNewInstance) {
            topLay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    homePagerAdapter.setTopHeight(topLay.getHeight() + tabLay.getHeight());
                }
            }, 500);
        } else {
            homePagerAdapter.setTopHeight(topLay.getHeight() + tabLay.getHeight());
        }
    }

    public int getCurrentSelectedIndex() {
        return home_content_vp.getCurrentItem();
    }

    /**
     * 切换到时讯新闻tab
     */
    public void setCurrentSelectIndex(int pos) {
        if (pos > 0) {
            home_content_vp.setCurrentItem(pos);
        }

    }

    /**
     * 切换到看电视中的广播
     */
    public void setCurrentTvAudioIndex() {
        int pos = homePagerAdapter.getPosCurrentPage(String.valueOf(HomePagerAdapter.TYPE_BTV));
        if (pos > 0) {
            home_content_vp.setCurrentItem(pos);
        }

    }

//    /**
//     * 切换到主播圈tab
//     */
//    public void setCurrentAnchorIndex() {
//        int pos = homePagerAdapter.getPosCurrentPage(String.valueOf(HomePagerAdapter.TYPE_ANCHOR));
//        if (pos > 0) {
//            home_content_vp.setCurrentItem(pos);
//        }
//
//    }

    /**
     * 切换到专题新闻tab
     */
    public void setCurrentSpecialIndex() {
        int pos = homePagerAdapter.getPosCurrentPage(String.valueOf(HomePagerAdapter.TYPE_SPECIAL));
        if (pos > 0) {
            home_content_vp.setCurrentItem(pos);
        }

    }

    private List<FocusColumn> compareSaveData2(List<FocusColumn> netList) {
        al_column = netList;
        if (netList.size() <= 6) {
            add_column.setVisibility(View.GONE);
            return netList;
        } else {
            String param = (String) SharedPreferencesUtil.getParam(getActivity(), COLUMN_LIST, "[]");
            ArrayList<String> selectIds = initGson().fromJson(param, new TypeToken<ArrayList<String>>() {
            }.getType());
            JLog.e("qwer   selectids=" + selectIds);
            if (ot_column == null) {
                ot_column = new ArrayList<>();
            } else {
                ot_column.clear();
            }
            ArrayList<String> idsTemp = new ArrayList<>(selectIds);
            ArrayList<FocusColumn> list = new ArrayList<>();
            String id = null;
            if (idsTemp.size() == 1) {
                id = idsTemp.get(0);
            }
            for (int i = 0; i < netList.size(); i++) {
                if (i < 6) {
                    list.add(netList.get(i));
                } else {
                    FocusColumn fc = netList.get(i);
                    ot_column.add(fc);
                    if (!TextUtils.isEmpty(id)) {
//                        if (TextUtils.equals(fc.getChannelId(),id)){
//
//                        }
                    } else {
                        if (idsTemp.size() > 0) {
                            for (int j = 0; j < idsTemp.size(); j++) {
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < selectIds.size(); i++) {

            }

            return list;
        }
    }

    /**
     * 与本地保存的数据相比较看那些数据是已经保存的
     *
     * @param netList
     * @return
     */
    private List<FocusColumn> compareSaveData(List<FocusColumn> netList) {
        ArrayList<FocusColumn> saveList = new ArrayList<>();
        String param = (String) SharedPreferencesUtil.getParam(getActivity(), COLUMN_LIST, "");
        if (!TextUtils.isEmpty(param)) {
            ArrayList<FocusColumn> focusColumns = initGson().fromJson(param, new TypeToken<ArrayList<FocusColumn>>() {
            }.getType());
            for (FocusColumn netColumn : netList) {
                int channelId = netColumn.getChannelId();
                for (int i = 0; i < focusColumns.size(); i++) {
                    if (channelId == focusColumns.get(i).getChannelId()) {
                        netColumn.setChoice(focusColumns.get(i).isChoice());
                    }
                    if ("12".equals(netColumn.getChannelType())) {
                        netColumn.setChoice(true);
                    } else if ("0".equals(netColumn.getChannelType())) {
                        netColumn.setChoice(true);
                    }
                }
                if (netColumn.isChoice()) {
                    saveList.add(netColumn);
                }
            }
            al_column = netList;
            String s = initGson().toJson(al_column);
            SharedPreferencesUtil.setParam(getActivity(), AddColumnActivity.COLUMN_LIST, s);
            if (ListUtils.isListValued(saveList)) {
                return saveList;
            } else {
                return noSaveColumn(netList);
            }
        } else {
            return noSaveColumn(netList);
        }
    }


    private ArrayList<FocusColumn> noSaveColumn(List<FocusColumn> netList) {
        al_column = netList;
        ArrayList<FocusColumn> list = new ArrayList<>();
        if (netList.size() > 7) {
            add_column.setVisibility(View.VISIBLE);
            for (int i = 0; i < netList.size(); i++) {
                if (i < 7) {
                    list.add(netList.get(i));
                    al_column.get(i).setChoice(true);
                } else {
                    al_column.get(i).setChoice(false);
                }
            }
        } else {
            add_column.setVisibility(View.GONE);
            list.addAll(netList);
            for (FocusColumn column : al_column) {
                column.setChoice(true);
            }
        }
        String s = initGson().toJson(al_column);
        SharedPreferencesUtil.setParam(getActivity(), AddColumnActivity.COLUMN_LIST, s);
        return list;
    }

    public boolean isShowLZ() {
        return isShowLZ;
    }

    /**
     * 每次点击首页tab的时候都加载到精选栏目
     */
    public void resetTabIndex() {
        currentTabPosition = 0;
        home_content_vp.setCurrentItem(currentTabPosition);

    }

    @Override
    public void onTabSelect(int position) {
        currentTabPosition = position;
        String id = getCurrentColumnId(position);
        Cache.getInstance().setCurrentChannelId(id);
        ColumnBaseFragment cbf = getCurrentFragment(position);
        if (cbf != null) {
            cbf.setParentShowing(true);
            cbf.onHiddenChanged(false);
        }
        JLog.e("home_tablay onTabSelect", "id = " + id);
        JLog.e("onTabSelect ", "position=" + position);
        if (home_content_vp != null) {
            String title = home_content_vp.getAdapter().getPageTitle(position).toString();
            JLog.e("home_tablay onTabSelect", "title = " + title);
            ArrayList<Pair<String, String>> pairs = new ArrayList<>();
            pairs.add(new Pair<>("页面", "首页"));
            pairs.add(new Pair<>("行为类型", "点击"));
            GridsumWebDissector.getInstance().trackEvent(this, "", title, "", 200, pairs);

        }
        if (position == 0 && isShowLZ) {
//            lzhomeLog.setVisibility(View.VISIBLE);
//            homeLog.setVisibility(View.GONE);
//            homeLogD.setVisibility(View.GONE);
            lzTitle.setVisibility(View.VISIBLE);
            normalTitle.setVisibility(View.GONE);
            titleTxt.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(Cache.getInstance().getChoosedCityIcon())) {
                GlideUtil.loadImgWith11DefTopImg(getContext(), Cache.getInstance().getChoosedCityIcon(), lzhomeLog);
            }
            titleTxt.setText(Cache.getInstance().getChoosedCityTitle());
            titleTxt.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        } else {
//            lzhomeLog.setVisibility(View.GONE);
//            homeLog.setVisibility(View.VISIBLE);
//            homeLogD.setVisibility(View.VISIBLE);
//            titleTxt.setVisibility(View.GONE);
            lzTitle.setVisibility(View.GONE);
            normalTitle.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onTabReselect(int position) {
        currentTabPosition = position;
        String id = getCurrentColumnId(position);
        Cache.getInstance().setCurrentChannelId(id);
        JLog.e("home_tablay onTabReselect", "id = " + id);

    }

    @Override
    public void onTabScrollTo(int position) {
        String id = getCurrentColumnId(position);
        Cache.getInstance().setCurrentChannelId(id);

    }


    public String getCurrentColumnId(int position) {
        if (!ListUtils.isListValued(thisColumnList)) {
            return "";
        } else {
            return "" + thisColumnList.get(position).getChannelId();
        }

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
//        LocationUtils.getInstance().unregisterOnLocatedListener(this);
    }

    public void setResetTab(boolean resetTab) {
        isResetTab = resetTab;
    }

    public String getAnouncementUrl() {
        return anouncementUrl;
    }

    public void setAnouncementUrl(String anouncementUrl) {
        this.anouncementUrl = anouncementUrl;
    }
}
